package flc.ast.adapter;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.blankj.utilcode.util.ConvertUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.SelectFileBean;
import flc.ast.bean.TransferRecordBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.view.container.StkRecycleView;

public class TransferRecordAdapter extends StkProviderMultiAdapter<TransferRecordBean> {

    public TransferRecordAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(40));
        addItemProvider(new TransferRecordProvider());
    }

    private boolean isEdit = false;

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class TransferRecordProvider extends BaseItemProvider<TransferRecordBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_transfer_record;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, TransferRecordBean bean) {
            baseViewHolder.setText(R.id.tvTransferRecordItemTime, bean.getTime());
            long size = 0;
            for (SelectFileBean selectFileBean : bean.getList()) {
                size += selectFileBean.getSize();
            }
            baseViewHolder.setText(R.id.tvTransferRecordItemDesc, bean.getList().size() + getContext().getString(R.string.file_count_text) + ConvertUtils.byte2FitMemorySize(size, 2));
            StkRecycleView recycleView;
            switch (bean.getType()) {
                case 1:
                    baseViewHolder.getView(R.id.rvTransferRecordItemImgList).setVisibility(View.VISIBLE);
                    baseViewHolder.getView(R.id.rvTransferRecordItemList).setVisibility(View.GONE);
                    recycleView = baseViewHolder.getView(R.id.rvTransferRecordItemImgList);
                    recycleView.setLayoutManager(new GridLayoutManager(getContext(), 3));
                    PictureRecordAdapter pictureAdapter = new PictureRecordAdapter();
                    pictureAdapter.setEdit(isEdit);
                    recycleView.setAdapter(pictureAdapter);
                    pictureAdapter.setList(bean.getList());
                    pictureAdapter.setOnItemClickListener(getOnItemClickListener());
                    break;
                case 2:
                    baseViewHolder.getView(R.id.rvTransferRecordItemImgList).setVisibility(View.VISIBLE);
                    baseViewHolder.getView(R.id.rvTransferRecordItemList).setVisibility(View.GONE);
                    recycleView = baseViewHolder.getView(R.id.rvTransferRecordItemImgList);
                    recycleView.setLayoutManager(new GridLayoutManager(getContext(), 3));
                    VideoRecordAdapter videoAdapter = new VideoRecordAdapter();
                    videoAdapter.setEdit(isEdit);
                    recycleView.setAdapter(videoAdapter);
                    videoAdapter.setList(bean.getList());
                    videoAdapter.setOnItemClickListener(getOnItemClickListener());
                    break;
                case 3:
                    baseViewHolder.getView(R.id.rvTransferRecordItemImgList).setVisibility(View.GONE);
                    baseViewHolder.getView(R.id.rvTransferRecordItemList).setVisibility(View.VISIBLE);
                    recycleView = baseViewHolder.getView(R.id.rvTransferRecordItemImgList);
                    recycleView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
                    AudioRecordAdapter audioAdapter = new AudioRecordAdapter();
                    audioAdapter.setEdit(isEdit);
                    recycleView.setAdapter(audioAdapter);
                    audioAdapter.setList(bean.getList());
                    audioAdapter.setOnItemClickListener(getOnItemClickListener());
                    break;
                case 4:
                    baseViewHolder.getView(R.id.rvTransferRecordItemImgList).setVisibility(View.GONE);
                    baseViewHolder.getView(R.id.rvTransferRecordItemList).setVisibility(View.VISIBLE);
                    recycleView = baseViewHolder.getView(R.id.rvTransferRecordItemImgList);
                    recycleView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
                    AppRecordAdapter appAdapter = new AppRecordAdapter();
                    appAdapter.setEdit(isEdit);
                    recycleView.setAdapter(appAdapter);
                    appAdapter.setList(bean.getList());
                    appAdapter.setOnItemClickListener(getOnItemClickListener());
                    break;
                case 5:
                    baseViewHolder.getView(R.id.rvTransferRecordItemImgList).setVisibility(View.GONE);
                    baseViewHolder.getView(R.id.rvTransferRecordItemList).setVisibility(View.VISIBLE);
                    recycleView = baseViewHolder.getView(R.id.rvTransferRecordItemImgList);
                    recycleView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
                    ContactsRecordAdapter contactsAdapter = new ContactsRecordAdapter();
                    contactsAdapter.setEdit(isEdit);
                    recycleView.setAdapter(contactsAdapter);
                    contactsAdapter.setList(bean.getList());
                    contactsAdapter.setOnItemClickListener(getOnItemClickListener());
                    break;
            }
        }
    }
}
